package com.lxd.sunso.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxd.sunso.product.entity.AlarmhisdataEntity;
import com.lxd.sunso.product.service.AlarmhisdataService;


import javax.servlet.http.HttpServletResponse;


/**
 * 
 *
 * @author lxd
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 18:06:30
 */
@RestController
@RequestMapping("product/alarmhisdata")
public class AlarmhisdataController {
    @Autowired
    private AlarmhisdataService alarmhisdataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:alarmhisdata:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = alarmhisdataService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:alarmhisdata:info")
    public R info(@PathVariable("id") Long id) {
        AlarmhisdataEntity alarmhisdata = alarmhisdataService.getById(id);

        return R.ok().put("alarmhisdata", alarmhisdata);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:alarmhisdata:save")
    public R save(@RequestBody AlarmhisdataEntity alarmhisdata) {
        alarmhisdataService.save(alarmhisdata);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:alarmhisdata:update")
    public R update(@RequestBody AlarmhisdataEntity alarmhisdata) {
        alarmhisdataService.updateById(alarmhisdata);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:alarmhisdata:delete")
    public R delete(@RequestBody Long[] ids) {
        alarmhisdataService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 搜索
     */
    @RequestMapping("/search")
    public R search(@RequestParam Map<String, Object> params) {
        PageUtils listAll = alarmhisdataService.search(params);
        return R.ok().put("data", listAll);
    }

    /**
     * 历史数据的导出
     */
    @RequestMapping("/export")
    public void exportExcel(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        try {
            alarmhisdataService.exportExcel(response, params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
